<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :destroyOnClose="true"
    @cancel="handleCancel"
    :footer="null">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-collapse v-model="activeKey">

          <a-collapse-panel :header="$t('light.basicConfiguration')" key="1">

            <a-row>
              <a-col :span="4">
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="readDate" type="primary" icon="plus" > {{$t('light.readDate')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 22 }">
                  <a-date-picker :placeholder="$t('light.pleaseSelectDateTime')"
                                 v-decorator="[ 'dateTime',validatorRules.dateTime]" :trigger-change="true"
                                 format="YYYY-MM-DD HH:mm:ss" />
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item  :wrapper-col="{ span: 14 }">
                <a-button @click="setDate" type="primary" icon="plus"> {{$t('light.writeDate')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="4" >
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="readLightGateWay" type="primary" icon="plus"> {{$t('light.readSubControlNetworkSegment')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item :label-col="{ span: 1 }" :wrapper-col="{ span: 22 }">
                  <a-input maxlength ="15"  v-decorator="[ 'lightGateWay', validatorRules.lightGateWay]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item  :wrapper-col="{ span: 14 }">
                  <a-button @click="setLightGateWay" type="primary" icon="plus"> {{$t('light.writeSubControlNetworkSegment')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="4">
                <a-form-item :label-col="{ span: 9 }" :wrapper-col="{ span: 15 }">
                  <a-button @click="getOpenStatus" type="primary" icon="plus"> {{$t('light.readSwitchStatus')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item  :wrapper-col="{ span: 22 }">
                  <a-input   v-decorator="[ 'openstatusvalue', validatorRules.openstatusvalue]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-button @click="setOpenStatus" type="primary" icon="plus"> {{$t('light.writeSwitchStatus')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.modeConfiguration') " key="9">
            <a-row style="text-align: center">
              <a-col :span="12">
                <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-button  @click="getTimeFrameAndDimming" type="primary" icon="plus"> {{$t('light.readPeriod')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                  <a-button @click="setTimeFrameAndDimming" type="primary" icon="plus" > {{$t('light.writePeriod')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row class="form-row" :gutter="16">
              <a-col :lg="12">

                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.sunriseTurnOffTime') " :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <j-dict-select-tag v-decorator="['typeb', validatorRules.typeb]" :triggerChange="true"
                                         :placeholder="$t('base.pleaseChoose')"
                                         dictCode="glr_pattern_time"/>
                    </a-form-item>
                  </a-col>
                  <a-col :span="9">
                    <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <j-dict-select-tag v-decorator="['timeb', validatorRules.timeb]" :triggerChange="true"
                                         :placeholder="$t('base.pleaseChoose')"
                                         dictCode="glr_gate_way_time"/>
                    </a-form-item>
                  </a-col>
                </a-row>

              </a-col>
              <a-col :lg="12">

                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.sunsetTurnOnTime') " :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <j-dict-select-tag v-decorator="['typec', validatorRules.typec]" :triggerChange="true"
                                         :placeholder="$t('base.pleaseChoose')"
                                         dictCode="glr_pattern_time"/>
                    </a-form-item>
                  </a-col>
                  <a-col :span="9">
                    <a-form-item :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <j-dict-select-tag v-decorator="['timec', validatorRules.timec]" :triggerChange="true"
                                         :placeholder="$t('base.pleaseChoose')"
                                         dictCode="glr_gate_way_time"/>
                    </a-form-item>
                  </a-col>
                </a-row>
              </a-col>
            </a-row>

            <a-row class="form-row" :gutter="16">

              <a-col :lg="12">
                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.period1') " :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <a-time-picker format="HH:mm" :minute-step="10" :second-step="10"  :allowClear="true" :inputReadOnly="true"  :placeholder="$t('base.pleaseChoose')"
                                     v-decorator="[ 'commandTimea', validatorRules.commandTimea]" :trigger-change="true"
                                     :disabledHours="getDisabledHours1"
                                     :disabledMinutes="getDisabledMinutes1"
                                     style="width: 100%" />
                    </a-form-item>
                  </a-col>
                  <a-col :lg="9">
                    <a-form-item  :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      (00:00-03:00)
                    </a-form-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :lg="12">
                <a-form-item :label=" $t('light.brightness') " :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input-number v-decorator="[ 'brightValuea', validatorRules.brightValuea]" :min=minbrightValue :max=maxbrightValue :placeholder="$t('base.pleaseEnter')" style="width: 100%"/>
                </a-form-item>
              </a-col>
            </a-row>


            <a-row class="form-row" :gutter="16">
              <a-col :lg="12">
                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.period2')" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <a-time-picker format="HH:mm" :minute-step="10" :second-step="10"  :allowClear="true" :inputReadOnly="true"  :placeholder="$t('base.pleaseChoose')"
                                     v-decorator="[ 'commandTimeb', validatorRules.commandTimeb]" :trigger-change="true"
                                     :disabledHours="getDisabledHours2"
                                     :disabledMinutes="getDisabledMinutes2"
                                     style="width: 100%" />
                    </a-form-item>
                  </a-col>
                  <a-col :span="9">
                    <a-form-item  :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      (03:01-08:00)
                    </a-form-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :lg="12">
                <a-form-item :label=" $t('light.brightness') " :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="[ 'brightValueb', validatorRules.brightValueb]"  :min=minbrightValue :max=maxbrightValue :placeholder="$t('base.pleaseEnter')" style="width: 100%"></a-input>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row class="form-row" :gutter="16">
              <a-col :lg="12">
                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.period3')" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <a-time-picker format="HH:mm" :minute-step="10" :second-step="10"  :allowClear="true" :inputReadOnly="true"  :placeholder="$t('base.pleaseChoose')"
                                     v-decorator="[ 'commandTimec', validatorRules.commandTimec]" :trigger-change="true"
                                     :disabledHours="getDisabledHours3"
                                     :disabledMinutes="getDisabledMinutes3"
                                     style="width: 100%" />
                    </a-form-item>
                  </a-col>
                  <a-col :span="9">
                    <a-form-item  :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      (17:00-20:00)
                    </a-form-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :lg="12">
                <a-form-item :label=" $t('light.brightness') " :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input-number v-decorator="[ 'brightValuec', validatorRules.brightValuec]" :min=minbrightValue :max=maxbrightValue :placeholder="$t('base.pleaseEnter')" style="width: 100%"/>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row class="form-row" :gutter="16">
              <a-col :lg="12">
                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.period4')" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <a-time-picker format="HH:mm" :minute-step="10" :second-step="10"  :allowClear="true" :inputReadOnly="true"  :placeholder="$t('base.pleaseChoose')"
                                     v-decorator="[ 'commandTimed', validatorRules.commandTimed]" :trigger-change="true"
                                     :disabledHours="getDisabledHours4"
                                     :disabledMinutes="getDisabledMinutes4"
                                     style="width: 100%" />
                    </a-form-item>
                  </a-col>
                  <a-col :span="9">
                    <a-form-item  :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      (20:01-22:00)
                    </a-form-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :lg="12">
                <a-form-item :label=" $t('light.brightness') " :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input-number v-decorator="[ 'brightValued', validatorRules.brightValued]" :min=minbrightValue :max=maxbrightValue :placeholder="$t('base.pleaseEnter')" style="width: 100%"/>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row class="form-row" :gutter="16">
              <a-col :lg="12">
                <a-row :gutter="24">
                  <a-col :span="15">
                    <a-form-item :label=" $t('light.period5') " :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      <a-time-picker format="HH:mm" :minute-step="10" :second-step="10"  :allowClear="true" :inputReadOnly="true"  :placeholder="$t('base.pleaseChoose')"
                                     v-decorator="[ 'commandTimee', validatorRules.commandTimee]" :trigger-change="true"
                                     :disabledHours="getDisabledHours5"
                                     :disabledMinutes="getDisabledMinutes5"
                                     style="width: 100%" />
                    </a-form-item>
                  </a-col>
                  <a-col :span="9">
                    <a-form-item  :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
                      (22:01-23:59)
                    </a-form-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :lg="12">
                <a-form-item :label=" $t('light.brightness') " :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input-number v-decorator="[ 'brightValuee', validatorRules.brightValuee]" :min=minbrightValue :max=maxbrightValue :placeholder="$t('base.pleaseEnter')" style="width: 100%"/>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item :label=" $t('light.sunriseTime') " :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
                  <a-input v-bind:readonly="true"  v-decorator="[ 'richu', validatorRules.richu]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item :label=" $t('light.sunsetTime') " :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
                  <a-input  v-bind:readonly="true" v-decorator="[ 'riluo', validatorRules.riluo]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>
            </a-row>


          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.ipConfiguration') " key="2" >
        <a-row style="text-align: center">
          <a-col :span="12" style="text-align: right" >
            <a-form-item :wrapper-col="{ span: 22 }">
              <a-button @click="setIP" type="primary" icon="plus"> {{$t('light.writeIP')}} </a-button>
            </a-form-item>
          </a-col>
          <a-col :span="12" style="text-align: left">
            <a-form-item :wrapper-col="{ span: 22 }">
              <a-button @click="getIP" type="primary" icon="plus"> {{$t('light.readIP')}} </a-button>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="8">
            <a-form-item  :label=" $t('light.network') " :label-col="{ span: 5 }" :wrapper-col="{ span: 10 }">
              <j-dict-select-tag  v-decorator="['netvalue', validatorRules.netvalue]" :triggerChange="true" :placeholder=" $t('light.networkType') "
                                  dictCode="glr_gate_way_network"/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item :label=" $t('light.ip') "  :label-col="{ span: 5}" :wrapper-col="{ span: 15 }">
              <a-input   v-decorator="[ 'ipvalue', validatorRules.ipvalue]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item :label=" $t('light.port') " :label-col="{ span: 5}" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'portvalue', validatorRules.portvalue]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.systemCycleConfiguration') " key="3" >
        <a-row style="text-align: center">
          <a-col :span="12" style="text-align: right" >
            <a-form-item :wrapper-col="{ span: 22 }">
              <a-button @click="setGateWayMsg" type="primary" icon="plus"> {{$t('light.systemCycleSet')}} </a-button>
            </a-form-item>
          </a-col>
          <a-col :span="12" style="text-align: left">
            <a-form-item :wrapper-col="{ span: 22 }">
              <a-button @click="getGateWayMsg" type="primary" icon="plus"> {{$t('light.systemCycleRead')}} </a-button>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <a-form-item  :label=" $t('light.heartbeatCycle') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'heartbeat', validatorRules.heartbeat]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label=" $t('light.dataCycle') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'dataCycle', validatorRules.dataCycle]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.measurementPeriod') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'testCycle', validatorRules.testCycle]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.pollingCycle') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'pollingCycle', validatorRules.pollingCycle]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.test') " key="4" >
        <a-row style="text-align: center">
          <a-col :span="12" style="text-align: right" >
            <a-form-item :wrapper-col="{ span: 22 }">
              <a-button @click="setPacketLoss" type="primary" icon="plus"> {{$t('light.startTesting')}} </a-button>
            </a-form-item>
          </a-col>
          <a-col :span="12" style="text-align: left">
            <a-form-item :wrapper-col="{ span: 22 }">
              <a-button @click="getPacketLoss" type="primary" icon="plus"> {{$t('light.getTestResults')}} </a-button>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="6">
            <a-form-item  :label=" $t('light.subControlSequenceNumber') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'lightCode', validatorRules.lightCode]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label=" $t('light.testTimes') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'testCount', validatorRules.testCount]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.testResult') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'testResult', validatorRules.testResult]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.testInterval') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'testTime', validatorRules.testTime]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.lonLatConfiguration') " key="5" >
        <a-row style="text-align: center">
          <a-col>
            <a-form-item>
              <a-button @click="getGPS" type="primary" icon="plus"> {{$t('light.readLonLat')}} </a-button>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="6">
            <a-form-item  :label=" $t('light.gpsTimingSwitch') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <j-dict-select-tag  v-decorator="['gpsTime', validatorRules.gpsTime]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                  dictCode="glr_on_off"/>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label=" $t('light.lonLatUpdateSwitch') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <j-dict-select-tag  v-decorator="['lgTime', validatorRules.lgTime]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                  dictCode="glr_on_off"/>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.minimumDimming') " :label-col="{ span: 12 }":wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'minDimming', {'initialValue':'00'}]" :placeholder="$t('base.pleaseEnter')" v-bind:readonly="true" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.longitude') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'longitude', validatorRules.longitude]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.latitude') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'latitude', validatorRules.latitude]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.altitude') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'altitude', validatorRules.altitude]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.searchForStars') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'gpsCam', validatorRules.gpsCam]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.periodLon') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'timeLongitude', validatorRules.timeLatitude]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item :label=" $t('light.periodLat') " :label-col="{ span: 12 }" :wrapper-col="{ span: 10 }">
              <a-input   v-decorator="[ 'timeLatitude', validatorRules.timeLongitude]" :placeholder="$t('base.pleaseEnter')"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.lightingConfiguration') " key="10" v-if="gateway0301">
            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setIlluminance" type="primary" icon="plus"> {{$t('light.setLighting')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getIlluminance" type="primary" icon="plus"> {{$t('light.readLight')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="8">
                <a-form-item  :label=" $t('light.lightSwitch') " :label-col="{ span: 6 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['onOff', validatorRules.onOff]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                      dictCode="glr_on_off"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item :label=" $t('light.illuminance') "  :label-col="{ span: 5}" :wrapper-col="{ span: 15 }">
                  <a-input   v-decorator="[ 'illuminance', validatorRules.illuminance]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="8" >
                <a-form-item :label=" $t('light.result') " :label-col="{ span: 5}" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'portvalue', validatorRules.portvalue]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.ratedPowerConfiguration') " key="22" v-if="false">

            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setRatedPower" type="primary" icon="plus"> {{$t('light.setRatedPower')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getRatedPower" type="primary" icon="plus"> {{$t('light.readRatedPower')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  :label=" $t('light.lamp1Power') " :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <a-select v-decorator="[ 'lightOneTypeCode', validatorRules.lightOneTypeCode]" :placeholder="$t('base.pleaseChoose')">
                    <a-select-option v-for="item in lightTypeList" :key="item.id" :value="item.power">
                      {{item.name}}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  :label=" $t('light.lamp2Power') " :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <a-select v-decorator="[ 'lightTwoTypeCode', validatorRules.lightTwoTypeCode]" :placeholder="$t('base.pleaseChoose')">
                    <a-select-option v-for="item in lightTypeList" :key="item.id" :value="item.power">
                      {{item.name}}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  :label=" $t('light.numberOfLights') " :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['lightNumber', validatorRules.lightNumber]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                      dictCode="glr_light_number"/>
                </a-form-item>
              </a-col>

            </a-row>
          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.subControlMACConfiguration') " key="232" v-if="false">

            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setSubControlMAC" type="primary" icon="plus"> {{$t('light.setSubControlMAC')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getSubControlMAC" type="primary" icon="plus"> {{$t('light.readSubControlMAC')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>

              <a-col :span="8" >
                <a-form-item :label=" $t('light.subControlSequenceNumber') " :label-col="{ span: 10}" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'subControlNo', validatorRules.subControlNo]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="8" >
                <a-form-item :label=" $t('light.MACLength') " :label-col="{ span: 10}" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'macLength', validatorRules.macLength]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="8" >
                <a-form-item :label=" $t('light.subControlSequenceNumber') " :label-col="{ span: 10}" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'macAddress', validatorRules.macAddress]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>

            </a-row>

          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.systemRestart') " key="23" v-if="gateway0301">

            <a-row style="text-align: center">
              <a-col>
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setSystemRestart" type="primary" icon="plus"> {{$t('light.systemRestart')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.firmwareUpdate') " key="231" v-if="gateway0301">

            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setFirmwareUpdate" type="primary" icon="plus"> {{$t('light.firmwareUpdate')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-badge status="warning" :text="alertMessage" v-show="alertVisible" style="float: left;"/>
                </a-form-item>
              </a-col>
            </a-row>


            <a-row>
              <a-col :span="8">
                <a-form-item  :label=" $t('light.controlWord') " :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['controlWord', validatorRules.controlWord]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                      dictCode="FirmwareUpdateControlWord"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-upload
                  name="file"
                  v-decorator="['file', {}]"
                  :action="uploadAction"
                  :headers="headers"
                  :fileList="fileList"
                  :multiple="true"
                  @change="handleChange"
                  accept=".*"
                >
                  <a-button> <a-icon type="upload" />  {{$t('light.uploadAttachment')}} </a-button>
                </a-upload>
              </a-col>
            </a-row>


          </a-collapse-panel>

          <a-collapse-panel :header=" $t('light.versionNumber') " key="24" v-if="gateway0301">
            <a-row style="text-align: center">
              <a-col>
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getVersionNo" type="primary" icon="plus"> {{$t('light.readVersionNumber')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>
              <a-col :span="8">
                <a-form-item  :label=" $t('light.hardwareVersion') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'hardwareVersion', validatorRules.hardwareVersion]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  :label=" $t('light.softwareVersion') " :label-col="{ span: 10 }" :wrapper-col="{ span: 10 }">
                  <a-input   v-decorator="[ 'softwareVersion', validatorRules.softwareVersion]" :placeholder="$t('base.pleaseEnter')"></a-input>
                </a-form-item>
              </a-col>

            </a-row>
          </a-collapse-panel>


          <a-collapse-panel :header=" $t('light.factorySettings') " key="25" v-if="false">

            <a-row style="text-align: center">
              <a-col :span="12" style="text-align: right" >
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="setManufacturerSet" type="primary" icon="plus"> {{$t('light.setFactorySettings')}} </a-button>
                </a-form-item>
              </a-col>
              <a-col :span="12" style="text-align: left">
                <a-form-item :wrapper-col="{ span: 22 }">
                  <a-button @click="getManufacturerSet" type="primary" icon="plus"> {{$t('light.readFactorySettings')}} </a-button>
                </a-form-item>
              </a-col>
            </a-row>

            <a-row>

              <a-col :span="8">
                <a-form-item  :label=" $t('light.heartbeatSwitch') " :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['heartbeatSwitch', validatorRules.heartbeatSwitch]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                      dictCode="glr_off_on"/>
                </a-form-item>
              </a-col>

              <a-col :span="8">
                <a-form-item  :label=" $t('light.uploadSwitch') " :label-col="{ span: 8 }" :wrapper-col="{ span: 10 }">
                  <j-dict-select-tag  v-decorator="['uploadSwitch', validatorRules.uploadSwitch]" :triggerChange="true" :placeholder="$t('base.pleaseChoose')"
                                      dictCode="glr_off_on"/>
                </a-form-item>
              </a-col>

            </a-row>


          </a-collapse-panel>

        </a-collapse>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import moment from 'moment'
  import {ACCESS_TOKEN} from "@/store/mutation-types"
  import { getUploadFileList,getFilePaths } from '@/utils/commonUploadFile.js'
  import Vue from 'vue'

  export default {
    name: "GlrGateWaySetParameter0101",
    components: {
      JDate,
    },
    data () {
      return {
        alertTimer:0,
        alertMessage:'',
        alertVisible:false,
        gateway0301:false,
        gateway0501:false,
        form: this.$form.createForm(this),
        title:"操作",
        width:1000,
        headers: {},
        fileList: [],
        fileMessage:'',
        activeKey: ['1'],
        visible: false,
        minbrightValue:0,
        maxbrightValue:100,
        gateWayCode:'',
        lightTypeList:[],
        disableMixinCreated:true,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          phoneNumber: {rules: [
            ]},
          phoneType: {rules: [
            ]},
          gatewayModel: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          gatewayType: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          longitude: {rules: [
            ]},
          latitude: {rules: [
            ]},
          gatewayName: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          gateWayCode: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          lightGateWay: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          openstatusvalue: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          netvalue: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          controlWord: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          ipvalue: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          portvalue: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          heartbeat: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          dataCycle: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          testCycle: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          pollingCycle: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          lightCode: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          testCount: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          testTime: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          onOff: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          illuminance: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          subControlNo: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          macLength: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          macAddress: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          heartbeatSwitch: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          uploadSwitch: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          gpsTime: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          lgTime: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          minDimming: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          longitude: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          latitude: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          altitude: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          gpsCam: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          timeLongitude: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          timeLatitude: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
          coordinateType: {rules: [
              {required: true, message: this.$t('base.pleaseChoose')+'!'},
            ]},
        },
        url: {
          add: "/glr/glrGateway/add",
          edit: "/glr/glrGateway/edit",
          readDate: "/glr/glrGateway/readDate",
          setDate: "/glr/glrGateway/setDate",
          readLightGateWay: "/glr/glrGateway/readLightGateWay",
          setLightGateWay: "/glr/glrGateway/setLightGateWay",
          getOpenStatus: "/glr/glrGateway/getOpenStatus",
          setOpenStatus: "/glr/glrGateway/setOpenStatus",
          getIP: "/glr/glrGateway/getIP",
          setIP: "/glr/glrGateway/setIP",
          getGateWayMsg: "/glr/glrGateway/getGateWayMsg",
          setGateWayMsg: "/glr/glrGateway/setGateWayMsg",
          getPacketLoss:"/glr/glrGateway/getPacketLoss",
          setPacketLoss:"/glr/glrGateway/setPacketLoss",
          getGPS:"/glr/glrGateway/getGPS",
          setGPS:"/glr/glrGateway/setGPS",
          getTimeFrameAndDimming:"/glr/glrGateway/getTimeFrameAndDimming",
          setTimeFrameAndDimming:"/glr/glrGateway/setTimeFrameAndDimming",
          getIlluminance:"/glr/glrGateway/getIlluminance",
          setIlluminance:"/glr/glrGateway/setIlluminance",
          getRatedPower:"/glr/glrGateway/getRatedPower",
          setRatedPower:"/glr/glrGateway/setRatedPower",
          getSubControlMAC:"/glr/glrGateway/getSubControlMAC",
          setSubControlMAC:"/glr/glrGateway/setSubControlMAC",
          getManufacturerSet:"/glr/glrGateway/getManufacturerSet",
          setManufacturerSet:"/glr/glrGateway/setManufacturerSet",
          setSystemRestart:"/glr/glrGateway/setSystemRestart",
          setFirmwareUpdate:"/glr/glrGateway/setFirmwareUpdate",
          getVersionNo:"/glr/glrGateway/getVersionNo",
          gatwWayUpload: window._CONFIG['domianURL']+"/glr/glrResource/gatwWayUpload",
          getLightType: "/glr/glrLightType/getLightType",
        }
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN);
      this.headers = {"X-Access-Token": token};
      const that = this;
      httpAction(that.url.getLightType,null,"post").then((res)=>{
        if(res.success){
          that.lightTypeList=res.result;
        }else{
          //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
        }
      }).finally(() => {
        that.confirmLoading = false;
      })
    },
    computed:{
      uploadAction:function () {
        return this.url.gatwWayUpload;
      }
    },
    methods: {
      add () {
        this.edit({});
      },
      alertTimerMethod(){
        var that = this;
        if (that.alertTimer>0){
          that.alertVisible=true;
          that.alertTimer=that.alertTimer -1;
          that.alertMessage=that.$t('light.firmwareUpdatePleaseWait') + that.formatSeconds(that.alertTimer)+"...";;
          setTimeout(that.alertTimerMethod, 1000);
        }else{
          that.alertTimer=0;
          that.alertMessage='';
          that.alertVisible=false;
        }
      },
      edit (record) {
        this.alertTimer=0;
        this.alertMessage='';
        this.alertVisible=false;
        //this.alertTimerMethod();

        this.fileList=[];
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.title=this.$t('light.gateWay')+":"+record.gatewayName+"("+record.gateWayCode+")";
        var gateWayCodeStart=record.gateWayCode.substring(0,4);
        this.gateway0301=false;
        if (gateWayCodeStart=="0101"||gateWayCodeStart=="0301"||gateWayCodeStart=="0501"||gateWayCodeStart=="0601"){
          this.gateway0301=true;
        }
        this.gateway0501=false;
        if (gateWayCodeStart=="0301"||gateWayCodeStart=="0501"||gateWayCodeStart=="0601"){
          this.gateway0501=true;
        }
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'gateWayCode'));
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      readDate(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.readDate, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
            that.form.setFieldsValue({'dateTime':moment(res.result.dateTime,'YYYY-MM-DD HH:mm:ss')});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setDate(){
        var that=this;
        that.confirmLoading = true;
        var dateTime=this.form.getFieldValue("dateTime");
        dateTime=moment(dateTime).format("YYYY-MM-DD HH:mm:ss");
        httpAction(that.url.setDate, {gateWayCode: this.model.gateWayCode,dateTime:dateTime}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      readLightGateWay(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.readLightGateWay, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
            that.form.setFieldsValue({'lightGateWay':res.result.data});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setLightGateWay(){
        var that=this;
        that.confirmLoading = true;
        this.form.validateFields(['lightGateWay'],(err, values) => {
          if (!err) {
            var lightGateWay = this.form.getFieldValue("lightGateWay");
            httpAction(that.url.setLightGateWay, {
              gateWayCode: this.model.gateWayCode,
              lightGateWay: lightGateWay
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }
        });
      },
        getOpenStatus(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getOpenStatus, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
            that.form.setFieldsValue({'openstatusvalue':res.result.data});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setOpenStatus(){

        this.form.validateFields(['openstatusvalue'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var openstatusvalue = this.form.getFieldValue("openstatusvalue");
            httpAction(that.url.setOpenStatus, {
              gateWayCode: this.model.gateWayCode,
              openstatusvalue: openstatusvalue
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getIP(){
        var that=this;
        that.confirmLoading = true;
        var netvalue=this.form.getFieldValue("netvalue");
        httpAction(that.url.getIP, {gateWayCode: this.model.gateWayCode,netvalue:netvalue}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
            var data=res.result.data;
              that.form.setFieldsValue({'netvalue':data.netvalue});
              that.form.setFieldsValue({'ipvalue':data.ipvalue});
              that.form.setFieldsValue({'portvalue':data.portvalue});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setIP(){
        this.form.validateFields(['netvalue','ipvalue','portvalue'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var netvalue = this.form.getFieldValue("netvalue");
            var ipvalue = this.form.getFieldValue("ipvalue");
            var portvalue = this.form.getFieldValue("portvalue");
            httpAction(that.url.setIP, {
              gateWayCode: this.model.gateWayCode,
              netvalue: netvalue,
              ipvalue: ipvalue,
              portvalue: portvalue
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      setIlluminance(){
        this.form.validateFields(['onOff','illuminance'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var onOff = this.form.getFieldValue("onOff");
            var illuminance = this.form.getFieldValue("illuminance");
            httpAction(that.url.setIlluminance, {
              gateWayCode: this.model.gateWayCode,
              onOff: onOff,
              illuminance: illuminance
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getIlluminance(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getIlluminance, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            that.form.setFieldsValue({'illuminanceValue':res.result.data});
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },

      setRatedPower(){
        this.form.validateFields(['lightOneTypeCode','lightTwoTypeCode','lightNumber'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var lightOneTypeCode = this.form.getFieldValue("lightOneTypeCode");
            var lightTwoTypeCode = this.form.getFieldValue("lightTwoTypeCode");
            var lightNumber = this.form.getFieldValue("lightNumber");
            httpAction(that.url.setRatedPower, {
              gateWayCode: this.model.gateWayCode,
              lightOneTypeCode: lightOneTypeCode,
              lightTwoTypeCode: lightTwoTypeCode,
              lightNumber: lightNumber,
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getRatedPower(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getRatedPower, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            var data=res.result.data;
            that.form.setFieldsValue({'lightOneTypeCode':data.lightOneTypeCode});
            that.form.setFieldsValue({'lightTwoTypeCode':data.lightTwoTypeCode});
            that.form.setFieldsValue({'lightNumber':data.lightNumber});
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setSubControlMAC(){
        this.form.validateFields(['subControlNo','macLength','macAddress'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var subControlNo = this.form.getFieldValue("subControlNo");
            var macLength = this.form.getFieldValue("macLength");
            var macAddress = this.form.getFieldValue("macAddress");
            httpAction(that.url.setSubControlMAC, {
              gateWayCode: this.model.gateWayCode,
              subControlNo: subControlNo,
              macLength: macLength,
              macAddress: macAddress,
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getSubControlMAC(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getSubControlMAC, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            var data=res.result.data;
            that.form.setFieldsValue({'subControlNo':data.subControlNo});
            that.form.setFieldsValue({'macLength':data.macLength});
            that.form.setFieldsValue({'macAddress':data.macAddress});
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },

      setManufacturerSet(){
        this.form.validateFields(['uploadSwitch','heartbeatSwitch'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var uploadSwitch = this.form.getFieldValue("uploadSwitch");
            var heartbeatSwitch = this.form.getFieldValue("heartbeatSwitch");
            httpAction(that.url.setManufacturerSet, {
              gateWayCode: this.model.gateWayCode,
              uploadSwitch: uploadSwitch,
              heartbeatSwitch: heartbeatSwitch,
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getManufacturerSet(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getManufacturerSet, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            var data=res.result.data;
            that.form.setFieldsValue({'uploadSwitch':data.uploadSwitch});
            that.form.setFieldsValue({'heartbeatSwitch':data.heartbeatSwitch});
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },

      getVersionNo(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getVersionNo, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            var data=res.result.data;
            that.form.setFieldsValue({'hardwareVersion':data.hardwareVersion});
            that.form.setFieldsValue({'softwareVersion':data.softwareVersion});
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setSystemRestart(){
        this.form.validateFields([],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            httpAction(that.url.setSystemRestart, {
              gateWayCode: this.model.gateWayCode,
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      formatSeconds(value) {
        let result = parseInt(value)
        let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
        let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
        let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));

        let res = '';
        if(h !== '00') res += `${h}` + this.$t('base.hour');
        if(m !== '00') res += `${m}` + this.$t('base.minute');
        res += `${s}` + this.$t('base.second');
        return res;
      },
      setFirmwareUpdate(){
        this.form.validateFields(['controlWord'],(err, values) => {
          if (!err) {
            if (this.fileMessage==""){
              this.$message.warning(this.$t('light.pleaseUploadFirmwareFile'))
              return ;
            }
            var that = this;
            that.confirmLoading = true;
            var controlWord = this.form.getFieldValue("controlWord");
            var uploadFilaName = this.fileMessage;
            httpAction(that.url.setFirmwareUpdate, {
              gateWayCode: this.model.gateWayCode,
              controlWord:controlWord,
              uploadFilaName:uploadFilaName,
            }, "post").then((res) => {
              if (res.success) {

                if (that.fileList.length>0){
                  var sss0=that.fileList[0].size/1024;
                  var sss1=(sss0/2)+10;
                  that.alertTimer=sss1;
                  that.alertTimer=parseInt(that.alertTimer);
                  that.alertMessage=that.$t('light.firmwareUpdatePleaseWait') + that.formatSeconds(that.alertTimer)+"...";
                  that.alertVisible=true;
                  that.alertTimerMethod();
                }

                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },

      getGateWayMsg(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getGateWayMsg, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
            var data=res.result.data;
              that.form.setFieldsValue({'heartbeat':data.heartBeat});
              that.form.setFieldsValue({'dataCycle':data.dataCycle});
              that.form.setFieldsValue({'testCycle':data.testCycle});
              that.form.setFieldsValue({'pollingCycle':data.pollingCycle});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setGateWayMsg(){
        this.form.validateFields(['heartbeat','dataCycle','testCycle','pollingCycle'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var heartbeat = this.form.getFieldValue("heartbeat");
            var dataCycle = this.form.getFieldValue("dataCycle");
            var testCycle = this.form.getFieldValue("testCycle");
            var pollingCycle = this.form.getFieldValue("pollingCycle");
            httpAction(that.url.setGateWayMsg, {
              gateWayCode: this.model.gateWayCode,
              heartBeat: heartbeat,
              dataCycle: dataCycle,
              testCycle: testCycle,
              pollingCycle: pollingCycle
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getPacketLoss(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getPacketLoss, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
            that.form.setFieldsValue({'testResult':res.result.data});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setPacketLoss(){
        this.form.validateFields(['lightCode','testCount','testTime'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var lightCode = this.form.getFieldValue("lightCode");
            var testCount = this.form.getFieldValue("testCount");
            var testTime = this.form.getFieldValue("testTime");
            httpAction(that.url.setPacketLoss, {
              gateWayCode: this.model.gateWayCode,
              lightCode: lightCode,
              testCount: testCount,
              testTime: testTime
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
                that.form.setFieldsValue({'lightGateWay': res.result.value});
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getGPS(){
        var that=this;
        that.confirmLoading = true;
        var gpsTime=this.form.getFieldValue("gpsTime");
        var lgTime=this.form.getFieldValue("lgTime");
        var minDimming=this.form.getFieldValue("minDimming");
        httpAction(that.url.getGPS, {gateWayCode: this.model.gateWayCode,gpsTime:gpsTime,lgTime:lgTime,minDimming:minDimming}, "post").then((res) => {
          if (res.success) {
            console.info(res.result.data);
            var data=res.result.data;
            //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
            that.form.setFieldsValue({'gpsTime':data.gpsTime});
            that.form.setFieldsValue({'lgTime':data.lgTime});
            //that.form.setFieldsValue({'minDimming':data.minDimming});
            that.form.setFieldsValue({'altitude':data.altitude});
            that.form.setFieldsValue({'longitude':data.longitude});
            that.form.setFieldsValue({'latitude':data.latitude});
            that.form.setFieldsValue({'gpsCam':data.gpsCam});
            that.form.setFieldsValue({'timeLongitude':data.timeLongitude});
            that.form.setFieldsValue({'timeLatitude':data.timeLatitude});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setGPS(){
        this.form.validateFields(['gpsTime','lgTime','minDimming','longitude','latitude','altitude','gpsCam','timeLongitude','timeLatitude','coordinateType'],(err, values) => {
          if (!err) {
            var that = this;
            that.confirmLoading = true;
            var gpsTime = this.form.getFieldValue("gpsTime");
            var lgTime = this.form.getFieldValue("lgTime");
            var minDimming = this.form.getFieldValue("minDimming");
            var longitude = this.form.getFieldValue("longitude");
            var latitude = this.form.getFieldValue("latitude");
            var altitude = this.form.getFieldValue("altitude");
            var gpsCam = this.form.getFieldValue("gpsCam");
            var timeLongitude = this.form.getFieldValue("timeLongitude");
            var timeLatitude = this.form.getFieldValue("timeLatitude");
            var coordinateType = this.form.getFieldValue("coordinateType");
            httpAction(that.url.setGPS, {
              gateWayCode: this.model.gateWayCode,
              gpsTime: gpsTime,
              lgTime: lgTime,
              minDimming: minDimming,
              longitude: longitude,
              latitude: latitude,
              altitude: altitude,
              gpsCam: gpsCam,
              timeLongitude: timeLongitude,
              timeLatitude: timeLatitude,
              coordinateType: coordinateType,
            }, "post").then((res) => {
              if (res.success) {
                //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
                that.form.setFieldsValue({'lightGateWay': res.result.value});
              } else {
                //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
              }
            }).finally(() => {
              that.confirmLoading = false;
            });
          }});
      },
      getTimeFrameAndDimming(){
        var that=this;
        that.confirmLoading = true;
        httpAction(that.url.getTimeFrameAndDimming, {gateWayCode: this.model.gateWayCode}, "post").then((res) => {
          if (res.success) {
            var data=res.result.data;
            //that.$message.success(res.message);
                that.$message.success(that.$t('base.operationSuccessful'));
            //var typeb=data.typeb;
            //var typebs=typeb.split(":");
            that.form.setFieldsValue({'typeb':data.typeb});
            that.form.setFieldsValue({'timeb':data.timeb});
            //var typec=data.typec;
            //var typecs=typec.split(":");
            that.form.setFieldsValue({'typec':data.typec});
            that.form.setFieldsValue({'timec':data.timec});

            that.form.setFieldsValue({'commandTimea':moment(data.commandTimea,'HH:mm')});
            that.form.setFieldsValue({'brightValuea':data.brightValuea});
            that.form.setFieldsValue({'commandTimeb':moment(data.commandTimeb,'HH:mm')});
            that.form.setFieldsValue({'brightValueb':data.brightValueb});
            that.form.setFieldsValue({'commandTimec':moment(data.commandTimec,'HH:mm')});
            that.form.setFieldsValue({'brightValuec':data.brightValuec});
            that.form.setFieldsValue({'commandTimed':moment(data.commandTimed,'HH:mm')});
            that.form.setFieldsValue({'brightValued':data.brightValued});
            that.form.setFieldsValue({'commandTimee':moment(data.commandTimee,'HH:mm')});
            that.form.setFieldsValue({'brightValuee':data.brightValuee});

            that.form.setFieldsValue({'richu':data.richu});
            that.form.setFieldsValue({'riluo':data.riluo});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      setTimeFrameAndDimming(){
        var that=this;
        that.confirmLoading = true;

        var commandTimea=this.form.getFieldValue("commandTimea");
        commandTimea=moment(commandTimea).format("HH:mm");
        var brightValuea=this.form.getFieldValue("brightValuea");

        var commandTimeb=this.form.getFieldValue("commandTimeb");
        commandTimeb=moment(commandTimeb).format("HH:mm");
        var brightValueb=this.form.getFieldValue("brightValueb");

        var commandTimec=this.form.getFieldValue("commandTimec");
        commandTimec=moment(commandTimec).format("HH:mm");
        var brightValuec=this.form.getFieldValue("brightValuec");

        var commandTimed=this.form.getFieldValue("commandTimed");
        commandTimed=moment(commandTimed).format("HH:mm");
        var brightValued=this.form.getFieldValue("brightValued");

        var commandTimee=this.form.getFieldValue("commandTimee");
        commandTimee=moment(commandTimee).format("HH:mm");
        var brightValuee=this.form.getFieldValue("brightValuee");

        var typeb=this.form.getFieldValue("typeb")
        var timeb=this.form.getFieldValue("timeb")
        var typec=this.form.getFieldValue("typec")
        var timec=this.form.getFieldValue("timec")

        var richu=this.form.getFieldValue("richu");
        var riluo=this.form.getFieldValue("riluo");

        httpAction(that.url.setTimeFrameAndDimming, {gateWayCode: this.model.gateWayCode,
          commandTimea:commandTimea,brightValuea:brightValuea,commandTimeb:commandTimeb,brightValueb:brightValueb,
          commandTimec:commandTimec,brightValuec:brightValuec,commandTimed:commandTimed,brightValued:brightValued,
          commandTimee:commandTimee,brightValuee:brightValuee,
          typeb:typeb,timeb:timeb,typec:typec,timec:timec,richu:richu,riluo:riluo,
        }, "post").then((res) => {
          if (res.success) {
            //that.$message.success(res.message);
            that.$message.success(that.$t('base.operationSuccessful'));
            that.form.setFieldsValue({'lightGateWay':res.result.value});
          } else {
            //that.$message.warning(res.message);
                      that.$message.warning(that.$t('base.operationFailed'));
          }
        }).finally(() => {
          that.confirmLoading = false;
        });
      },
      handleChange(info) {
        this.fileMessage="";
        if (info.file.status === 'uploading') {
          this.fileList = info.fileList;
          return
        }
        if (info.file.status === 'removed') {
          this.fileList=info.fileList;
          return
        }
        if (info.file.status === 'done') {
          this.fileList = info.fileList;
          var response = info.file.response;
          if (!response.success) {
            this.$message.warning(response.message);
          }else {
            this.fileMessage=response.message;
          }
        }
      },
      beforeUpload(file) {
        var isJPG=false;
        var fileType=file.type.toLowerCase();
        if(fileType.indexOf('jpeg')!=-1){
          isJPG=true;
        }else if(fileType.indexOf('png')!=-1){
          isJPG=true;
        }else if(fileType.indexOf('mp4')!=-1) {
          isJPG=true;
        }else if(fileType.indexOf('jpg')!=-1) {
          isJPG=true;
        }else if(fileType.indexOf('gif')!=-1) {
          isJPG=true;
        }
        if(!isJPG){
          this.$message.error('只能上传mp4、jpg、gif、png、jpeg格式的文件,单个文件最大不能超过200MB');
          this.fileList=[];
          return false;
        }
        var isLt2M = true;
        if ((file.size / 1024 / 1024)>200) {
          this.$message.error('单个文件最大不能超过200MB!');
          this.fileList=[];
          return false;
        }
        if(isJPG && isLt2M){
          return true;
        }
      },



      getDisabledHours1 () {
        let hours = []
        hours.push(4)
        hours.push(5)
        hours.push(6)
        hours.push(7)
        hours.push(8)
        hours.push(9)
        hours.push(10)
        hours.push(11)
        hours.push(12)
        hours.push(13)
        hours.push(14)
        hours.push(15)
        hours.push(16)
        hours.push(17)
        hours.push(18)
        hours.push(19)
        hours.push(20)
        hours.push(21)
        hours.push(22)
        hours.push(23)
        return hours
      },
      getDisabledMinutes1 (selectedHour) {
        let minutes = []
        if (selectedHour == 3) {
          minutes.push(10)
          minutes.push(20)
          minutes.push(30)
          minutes.push(40)
          minutes.push(50)
        }
        return minutes
      },
      getDisabledHours2 () {
        let hours = []
        hours.push(0)
        hours.push(1)
        hours.push(2)
        hours.push(9)
        hours.push(10)
        hours.push(11)
        hours.push(12)
        hours.push(13)
        hours.push(14)
        hours.push(15)
        hours.push(16)
        hours.push(17)
        hours.push(18)
        hours.push(19)
        hours.push(20)
        hours.push(21)
        hours.push(22)
        hours.push(23)
        return hours
      },
      getDisabledMinutes2 (selectedHour) {
        let minutes = []
        if (selectedHour == 8) {
          minutes.push(10)
          minutes.push(20)
          minutes.push(30)
          minutes.push(40)
          minutes.push(50)
        }
        return minutes
      },
      getDisabledHours3 () {
        let hours = []
        hours.push(0)
        hours.push(1)
        hours.push(2)
        hours.push(3)
        hours.push(4)
        hours.push(5)
        hours.push(6)
        hours.push(7)
        hours.push(8)
        hours.push(9)
        hours.push(10)
        hours.push(11)
        hours.push(12)
        hours.push(13)
        hours.push(14)
        hours.push(15)
        hours.push(16)
        hours.push(21)
        hours.push(22)
        hours.push(23)
        return hours
      },
      getDisabledMinutes3 (selectedHour) {
        let minutes = []
        if (selectedHour == 20) {
          minutes.push(10)
          minutes.push(20)
          minutes.push(30)
          minutes.push(40)
          minutes.push(50)
        }
        return minutes
      },
      getDisabledHours4 () {
        let hours = []
        hours.push(0)
        hours.push(1)
        hours.push(2)
        hours.push(3)
        hours.push(4)
        hours.push(5)
        hours.push(6)
        hours.push(7)
        hours.push(8)
        hours.push(9)
        hours.push(10)
        hours.push(11)
        hours.push(12)
        hours.push(13)
        hours.push(14)
        hours.push(15)
        hours.push(16)
        hours.push(17)
        hours.push(18)
        hours.push(19)
        hours.push(23)
        return hours
      },
      getDisabledMinutes4 (selectedHour) {
        let minutes = []
        if (selectedHour == 22) {
          minutes.push(10)
          minutes.push(20)
          minutes.push(30)
          minutes.push(40)
          minutes.push(50)
        }
        return minutes
      },
      getDisabledHours5 () {
        let hours = []
        hours.push(0)
        hours.push(1)
        hours.push(2)
        hours.push(3)
        hours.push(4)
        hours.push(5)
        hours.push(6)
        hours.push(7)
        hours.push(8)
        hours.push(9)
        hours.push(10)
        hours.push(11)
        hours.push(12)
        hours.push(13)
        hours.push(14)
        hours.push(15)
        hours.push(16)
        hours.push(17)
        hours.push(18)
        hours.push(19)
        hours.push(20)
        hours.push(21)
        return hours
      },
      getDisabledMinutes5 (selectedHour) {
        let minutes = []
        if (selectedHour == 24) {
          minutes.push(10)
          minutes.push(20)
          minutes.push(30)
          minutes.push(40)
          minutes.push(50)
        }
        return minutes
      },


    }
  }
</script>